package cn.yun.web.servlet;

import cn.yun.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by pc on 2021/1/15 23:17
 * Description: LearningJava
 */
@WebServlet("/successServlet")
public class SuccessServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //获取request域中共享的数据
        User user =(User) request.getAttribute("user");
        if(user!= null){
            String username = user.getUsername();

            //给页面写一句话
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write("登录成功!"+username+",欢迎您");
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       this.doPost(request,response);
    }
}
